/*
 * Copyright 2012 Chris Uyehara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.chrisuyehara.vista.rpc.procedures;

import java.util.ArrayList;
import java.util.List;

import com.chrisuyehara.vista.rpc.parameters.Parameter;


/**
 * Class description
 *
 *
 * @version        v1.0, 2014-01-20
 * @author         Jim Horner
 */
public abstract class AbstractRemoteProcedure implements IRemoteProcedure {

    /** Field description */
    private final List<Parameter> parameterList;

    /** Field description */
    private String response;

    /** Field description */
    private final String rpcName;

    /**
     * Constructs ...
     *
     *
     * @param rpcName
     */
    public AbstractRemoteProcedure(String rpcName) {

        super();
        this.rpcName = rpcName;
        this.parameterList = new ArrayList<>();
    }

    /**
     * Method description
     *
     *
     * @param p
     */
    protected void addParameter(Parameter p) {

        this.parameterList.add(p);

    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public String getResponse() {
        return response;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getRpcName() {
        return rpcName;
    }

    /**
     * Method description
     *
     *
     * @param response
     */
    @Override
    public void setResponse(String response) {
        this.response = response;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public final String toProcedure() {

        return PayloadBuilder.build(this.rpcName, this.parameterList);
    }
}
